#include <iostream>
#include <csignal>
#include <thread>
#include <mutex>

#include "server.h"
#include "io_context_pool.h"
#include "singleton.hpp"

int main(void)
{
    try
    {   
        boost::asio::io_context io;

        boost::asio::signal_set signals(io, SIGINT, SIGTERM);
        signals.async_wait([&io](auto, auto){ 
            Singleton<IOContextPool>::GetInstance()->stop(); 
            std::cout << "Stopping server..." << std::endl; 
            io.stop(); 
        });

        Server server(io, 12345);
        io.run();
    }
    catch (const std::exception& e)
    {
        std::cerr << e.what() << std::endl;
    }

    return 0;
}